var putUploadFile = function() {
    describe('putUploadFile方法', function () {
        describe('上传ArrayBuffer文件,设置acl为public-read,并通过请求头设置存储类型为ARCHIVE', function () {
            let key = '1.mp4';
            var buf = new ArrayBuffer(8);
            var blob = new Blob([buf]);
            it('上传文件', function (done) {
                this.timeout(8000);
                var lastPercent = 0;
                ks3.putUploadFile({
                    key,
                    body: blob,
                    acl: 'public-read',
                    headers: {
                        'x-kss-storage-class': 'ARCHIVE'
                    },
                    onProgress: function (info) {
                        lastPercent = info.percent;
                    },
                }, (err, res) => {
                    should.not.exist(err);
                    lastPercent.should.be.equal(1);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取该文件的ACL', function (done) {
                this.timeout(2000);
                ks3.getObjectAcl({
                    key
                }).then(res => {
                    let grant = res.body.AccessControlPolicy.AccessControlList.Grant;
                    grant[0].Permission.should.be.equal('FULL_CONTROL');
                    grant[1].Permission.should.be.equal('READ');
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取文件的存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = res.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    object.StorageClass.should.be.equal('ARCHIVE');
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除该文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('上传文件空文件', function () {
            let key = 'empty.txt';
            var file = '';
            it('上传空文件', function (done) {
                this.timeout(8000);
                ks3.putUploadFile({
                    key,
                    body: file,
                    acl: 'public-read',
                    headers: {
                        'x-kss-storage-class': 'ARCHIVE'
                    }
                }, (err, res) => {
                    console.log('错误：', err)
                    console.log('结果：', res)
                    should.not.exist(err);
                    res.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('删除该文件', function (done) {
                this.timeout(2000);
                ks3.delObject({
                    key
                }).then(res => {
                    should.not.exist(res.error);
                    res.statusCode.should.be.equal(204);
                    done();
                })
            })
        })
        describe('上传文件过程可以被取消', function () {
            var key = '10m.zip';
            var alive = false;
            var canceled = false;
            var taskId;
            it('上传文件正常取消', function (done) {
                this.timeout(8000);
                ks3.putUploadFile({
                    key: key,
                    body: blob({ size: 1024 * 1024 * 2 }),
                    onTaskReady: function (_taskId) {
                        taskId = _taskId;
                    },
                    onProgress: function (info) {
                        alive = true;
                        console.log('上传进度', info)
                        if (!canceled) {
                            if (info.percent > 0.5) {
                                ks3.cancelTask(taskId);
                                canceled = true;
                                alive = false;
                                setTimeout(() => {
                                    console.log('当前alive上传状态', alive)
                                    alive.should.be.equal(false);
                                    done();
                                }, 2000)
                            }
                        }
                    }
                }, (err, res) => {
                    alive = true;
                })
            })
        })
    })
}